<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<script src="bootstrap/js/jquery-1.12.4.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
<script src="js/ejs.min.js"></script>
<script>ejs.delimiter = '$';</script>
<script src="js/date.js"></script>
<title>提问</title>
<script id="users" type="text/template">
      <$ if (info.length) { $>
          <$ info.forEach(function(item,index,arr){ $>  
		<$ if(index==1){$>	
		<img src="../<$=item$>" width="50px" height="50px"/>
			<$}else{$>
				<$=item$><br>
			<$}$>
    	<$ }) $>
      <$ } $>
</script>
<script id="ques" type="text/template">
      <$ if (que.length) { $>
         <$ que.forEach(function(item,index,arr){ $>  
		<$ if(index==0){$>	
		<h3><$=item$></h3><br>
			<$}else{$>
				<$=item$><br>
			<$}$>
    	<$ }) $>
      <$ } $>
</script>
<script type="text/javascript">
	function baocun() {
		var obj = new Object();
		obj.quesTitle = $("#title").val();
		obj.quesDesc = $("#desc").val();
		if (!obj.quesTitle.trim()) {
			alert("标题不能为空");
			return false;
		}

		if (!/[\w\W]{5,}/.test(obj.quesTitle)) {
			alert("标题不能少于五个字");
			return false;
		}

		$.post("Question2/insertQuestion2", obj, function(result) {
			var question = result.data.question;
			var userInfo = result.data.userInfo;
			var date = format(question.qUpdateTime);
			//用户信息
			var info = [ userInfo.uName, userInfo.uPhoto, userInfo.uAutoragh ];
			var users = document.getElementById('users').innerHTML;
			var html1 = ejs.render(users, {
				info : info
			});
			document.getElementById("user").innerHTML = html1;
			//问题信息
			var que = [ question.quesTitle, date, question.quesDesc ];
			var ques = document.getElementById('ques').innerHTML;
			var html2 = ejs.render(ques, {
				que : que
			});
			document.getElementById("quest").innerHTML = html2;
		}, 'json');
	}
</script>
</head>
<body>
	<div>
		<!-- Button trigger modal -->
		<button type="button" class="btn btn-primary btn-lg"
			data-toggle="modal" data-target="#myModal">提问</button>

		<div id="user"></div>
		<div id="quest"></div>
		<!-- Modal -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">问题</h4>
			</div>
			<div class="modal-body">
				标题<br> <input type="text" name="title" id="title"><span></span><br>
				描述(可选)<br> <input type="text" name="desc" id="desc"><br>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<input type="button" class="btn btn-primary" onclick="baocun()"
					data-dismiss="modal" value="提交" />
			</div>
		</div>
	</div>
</div>
	</div>
</body>
</html>